<div id="map2" style="height: 100%;width:100%">

</div>

<script type="text/javascript">
    function oldMaps2(type) {
        $.ajax({
            url: "#springUrl('/network/supply/costing/getDataMap2')",
            data: {"batchId": "","type":type,"selected":""},
            type: "POST",
            success: function (text) {
                var d2 = JSON.parse(text);
                if (d2.success && d2.data) {
                    var myChart = echarts.init(document.getElementById('map2'), 'macarons');
                    var planePath = 'path://M1705.06,1318.313v-89.254l-319.9-221.799l0.073-208.063c0.521-84.662-26.629-121.796-63.961-121.491c-37.332-0.305-64.482,36.829-63.961,121.491l0.073,208.063l-319.9,221.799v89.254l330.343-157.288l12.238,241.308l-134.449,92.931l0.531,42.034l175.125-42.917l175.125,42.917l0.531-42.034l-134.449-92.931l12.238-241.308L1705.06,1318.313z';
                    var color = ['#a6c84c', '#ffa022', '#46bee9', '#D1E9B1', '#7DFF21'];
                    var series = [];
                    var legend = [];
                    console.log(d2.data.map2);
                    var convertData = function (data) {
                        var res = [];
                        for (var i = 0; i < data.length; i++) {
                            var dataItem = data[i];
                            var fromCoord = d2.data.map1[dataItem[0].name];
                            var toCoord = d2.data.map1[dataItem[1].name];
                            if (fromCoord && toCoord) {
                                res.push({
                                    fromName: dataItem[0].name,
                                    toName: dataItem[1].name,
                                    coords: [fromCoord, toCoord]
                                });
                            }
                        }
                        return res;
                    };

                    d2.data.map2.forEach(function (item, i) {
                        series.push({
                                name: item[0] ,
                                type: 'lines',
                                zlevel: 1,
                                effect: {
                                    show: true,
                                    period: 10,
                                    trailLength: 0.7,
                                    color: '#fff',
                                    symbolSize: 2
                                },
                                lineStyle: {
                                    normal: {
                                        color: color[i],
                                        width: 0,
                                        curveness: 0.2
                                    }
                                },
                                data: convertData(item[1])
                            },
                            {
                                name: item[0] ,
                                type: 'lines',
                                zlevel: 2,
                                symbol: ['none', 'arrow'],
                                symbolSize: 1,
                                effect: {
                                    show: true,
                                    period: 10,
                                    trailLength: 0,
                                  //  symbol: planePath,
                                    symbolSize: 2
                                },
                                lineStyle: {
                                    normal: {
                                        color: color[i],
                                        width: 1,
                                        opacity: 0.6,
                                        curveness: 0.2
                                    }
                                },
                                data: convertData(item[1])
                            },
                            {
                                name: item[0] ,
                                type: 'effectScatter',
                                coordinateSystem: 'geo',
                                zlevel: 2,
                                rippleEffect: {
                                    brushType: 'stroke'
                                },
                                label: {
                                    normal: {
                                        show: true,
                                        position: 'right',
                                        formatter: '{b}'
                                    }
                                },
                                symbolSize: function (val) {
                                    return val[2] / 8;
                                },
                                itemStyle: {
                                    normal: {
                                        color: color[i]
                                    }
                                },
                                data: item[1].map(function (dataItem) {
                                    return {
                                        name: dataItem[1].name,
                                        value: d2.data.map1[dataItem[1].name].concat([dataItem[1].value])
                                    };
                                })
                            });
                    });

                    var option = {
                        backgroundColor: '#404a59',
                        title : {
                            // text: '模拟迁徙',
                            //  subtext: '数据纯属虚构',
                            left: 'center',
                            textStyle : {
                                color: '#fff'
                            }
                        },
                        tooltip : {
                            trigger: 'item'
                        },
                        legend: {
                            orient: 'vertical',
                            top: 'bottom',
                            left: 'right',
                            //  data:['北京 Top10', '上海 Top10', '广州 Top10'],
                            textStyle: {
                                color: '#fff'
                            },
                            selectedMode: true,
                        },
                        geo: {
                            map: 'china',
                            label: {
                                emphasis: {
                                    show: true
                                }
                            },
                            roam: true,
                            itemStyle: {
                                normal: {
                                    areaColor: '#323c48',
                                    borderColor: '#404a59'
                                },
                                emphasis: {
                                    areaColor: '#2a333d'
                                }
                            }
                        },
                        series: series
                    };

                    myChart.setOption(option);
                }else{
                    toastr.error('没有数据，请上传配送中心数据');
                    var div1="<div type='text' style='padding-top:18%' class=' text-center '>"+d.message+"</div>";
                    document.getElementById('map1').innerHTML=div1;
                }
            }
        });
    }

</script>